home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 1132 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.2 KB

  1. Path: news.iag.net!news
  2. From: jatmon@iag.net (John R Buchan)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Array of pointers to a tree structure ?
  5. Date: 11 Jan 1996 16:57:19 GMT
  6. Organization: Internet Access Group, Orlando, Florida
  7. Distribution: world
  8. Message-ID: <4d3fhf$9fl@news.iag.net>
  9. References: <4d067t$9lc@hermes.fundp.ac.be> <nxRvQDA1468wEw$$@harden.demon.co.uk>
  10. NNTP-Posting-Host: pm3-orl4.iag.net
  11. X-Newsreader: WinVN 0.99.7
  12.  
  13. In article <nxRvQDA1468wEw$$@harden.demon.co.uk>, mark@harden.demon.co.uk 
  14. says...
  15. >
  16. >In article <4d067t$9lc@hermes.fundp.ac.be>, Francisco Melo Ledermann
  17. <snip>
  18. >>/* BOXES STRUCTURE FOR THE CONSTRUCTION OF A TREE */
  19. >>
  20. >>struct boxes {
  21. >>              int number;
  22. >>              struct boxes *pointer_1;
  23. >>              struct boxes *pointer_2;
  24. >>              struct boxes *pointer_3;
  25. >>             }
  26. >>
  27. >>/* ARRAY OF POINTERS TO BOXES STRUCTURE FOR MANAGE */
  28. >>/* SOME BRANCHES OF THE TREE                       */
  29. >>
  30. >>struct boxes array_pointers [15];
  31. >
  32. >Should be "strut boxes *array_pointers [15];" otherwise you are defining
  33. >an array of structures.
  34. <snip>
  35. >        *array_pointers [3]->number = 13;
  36.  
  37. The array element '[]' and pointer to structure member '->' operators have 
  38. a higher precedence than the dereference '*'.  So this is equivalent to:
  39.  
  40.         *(array_pointers [3]->number) = 13;
  41.  
  42. Which generates an illegal dereference.  I suspect that you intended:
  43.  
  44.         (*array_pointers [3])->number = 13;
  45.  
  46. But this won't work either.  It gets and dereferences the third element
  47. in the pointer array.  You are now dealing with a struct, not a pointer.
  48. So you should use '.', not '->'.  Try:
  49.  
  50.         (*array_pointers [3]).number = 13;
  51. or
  52.         array_pointers [3]->number = 13;
  53.     
  54. >
  55. >To set "pointer_1" in the structure pointed to be array element 3 to
  56. >that pointed to by array element 4 you would :-
  57. >
  58. >        *array_pointers [3]->pointer_1 = array_pointers [4]; 
  59.  
  60. Hmm... I forgot that method in my examples.  However make it:
  61.  
  62.         array_pointers [3]->pointer_1 = array_pointers [4]; 
  63. or
  64.         (*array_pointers [3]).pointer_1 = array_pointers [4]; 
  65.  
  66.  
  67. -- 
  68. John R Buchan           -:|:-     Looking for that elusive FAQ?  ftp to:
  69. jatmon@mail.iag.net     -:|:-     rtfm.mit.edu /pub/usenet-by-group/....
  70.  
  71.